'
' Copyright (c) 2004-2005
' by Peter Donker ( info@bring2mind.net )
'
' Permission is hereby granted to use and/or modify this software for a single server. It is 
' NOT permitted to publish, distribute, sublicense, and/or sell copies of this software in its
' original or modified form. You are not allowed to remove this copyright notice.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
' BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
' NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
' DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF THE SOFTWARE.
'
Imports System
Imports System.Web.UI.WebControls
Imports DotNetNuke
Imports Bring2mind.DNN.Modules.Guestbook.Business

Namespace Bring2mind.DNN.Modules.Guestbook.Controls

 Public Class Settings
  Inherits Entities.Modules.ModuleSettingsBase

#Region " Controls "
  Protected WithEvents ctlAuthAddRoles As Controls.RoleListControl
  Protected WithEvents txtPageSize As System.Web.UI.WebControls.TextBox
  Protected WithEvents txtNotificationEmail As System.Web.UI.WebControls.TextBox
  Protected WithEvents ddDateFormat As System.Web.UI.WebControls.DropDownList
  Protected WithEvents chkAllowPictures As System.Web.UI.WebControls.CheckBox
  Protected WithEvents chkAllowHtml As System.Web.UI.WebControls.CheckBox
  Protected WithEvents txtMaxPictureSize As System.Web.UI.WebControls.TextBox
  Protected WithEvents txtMaxThumbnailSize As System.Web.UI.WebControls.TextBox
  Protected WithEvents ddApprovalRole As System.Web.UI.WebControls.DropDownList
#End Region

#Region " Base Method Implementations "
  Public Overrides Sub LoadSettings()
   Try
    If Not Page.IsPostBack Then
     Dim Settings As New ModuleSettings(Me.ModuleId)
     Dim formats() As String = Services.Localization.Localization.GetString("AvailableFormats", Me.LocalResourceFile).Split(New Char() {";"c})
     Dim format As String
     For Each format In formats
      ddDateFormat.Items.Add(New ListItem(Now.ToString(format), format))
     Next
     With Settings
      ctlAuthAddRoles.Assigned = .Roles
      ctlAuthAddRoles.Available = Me.PortalRoles
      txtPageSize.Text = .PageSize.ToString
      txtNotificationEmail.Text = .NotificationEmail
      Try
       ddDateFormat.Items.FindByValue(.DateFormat).Selected = True
      Catch ex As Exception
      End Try
      chkAllowHtml.Checked = .AllowHtml
      chkAllowPictures.Checked = .AllowPictures
      txtMaxPictureSize.Text = .MaxPictureSize.ToString
      txtMaxThumbnailSize.Text = .ThumbnailSize.ToString
     End With
     Dim objRoles As New DotNetNuke.Security.Roles.RoleController
     With ddApprovalRole
      .DataSource = objRoles.GetPortalRoles(PortalId)
      .DataBind()
      .Items.Insert(0, New ListItem("<" + Services.Localization.Localization.GetString("None_Specified") + ">", "-1"))
      Try
       .Items.FindByValue(Settings.ApprovalRole.ToString).Selected = True
      Catch ex As Exception
      End Try
     End With
    End If
   Catch exc As Exception
    ProcessModuleLoadException(Me, exc)
   End Try
  End Sub

  Public Overrides Sub UpdateSettings()
   Try

    Dim Settings As New ModuleSettings(Me.ModuleId)
    With Settings
     .Roles = ctlAuthAddRoles.Assigned
     .PageSize = Integer.Parse(txtPageSize.Text)
     .NotificationEmail = txtNotificationEmail.Text
     .DateFormat = ddDateFormat.SelectedValue
     .ApprovalRole = Integer.Parse(ddApprovalRole.SelectedValue)
     .AllowHtml = chkAllowHtml.Checked
     .AllowPictures = chkAllowPictures.Checked
     .MaxPictureSize = Integer.Parse(txtMaxPictureSize.Text)
     .ThumbnailSize = Integer.Parse(txtMaxThumbnailSize.Text)
     .SaveSettings(Me.ModuleId)
    End With
    'Me.Cache.Remove("Settings4Module" & Me.ModuleId & "inPortal" & Me.PortalId & "User" & Me.UserId.ToString)
    Me.Session.Clear()
    Response.Redirect(NavigateURL(), True)
   Catch exc As Exception
    ProcessModuleLoadException(Me, exc)
   End Try
  End Sub

#End Region

#Region " Private Methods "
  Private ReadOnly Property PortalRoles() As ArrayList
   Get

    'make the portal roles
    Dim objRoles As New DotNetNuke.Security.Roles.RoleController
    Dim objRole As DotNetNuke.Security.Roles.RoleInfo
    Dim arrRoles As ArrayList = objRoles.GetPortalRoles(PortalId)
    PortalRoles = New ArrayList
    PortalRoles.Add(New ListItem("All Users", DotNetNuke.Common.glbRoleAllUsers))
    For Each objRole In arrRoles
     PortalRoles.Add(New ListItem(objRole.RoleName, objRole.RoleID.ToString))
    Next

   End Get
  End Property
#End Region

#Region " Web Form Designer Generated Code "

  'This call is required by the Web Form Designer.
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

  End Sub

  Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
   'CODEGEN: This method call is required by the Web Form Designer
   'Do not modify it using the code editor.
   InitializeComponent()
  End Sub

#End Region

 End Class

End Namespace


